package com.zzh.service.impl.authentication;

import com.alibaba.fastjson.JSON;
import com.zzh.entity.Result;
import com.zzh.utils.ResultUtil;
import com.zzh.utils.WebUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wenrouyue
 * @FileName: AccessDeniedHandlerImpl
 * @description
 * @create 2023/2/10-17:59
 **/
@Service
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) {
        Result<String> error = ResultUtil.getError(HttpStatus.FORBIDDEN.value(), "权限不足!", "权限不足!");
        String rToString = JSON.toJSONString(error);
        WebUtils.renderString(response, rToString);
    }
}
